import { defineStore } from "pinia";
import { ref } from "vue";
import { getLoginUser } from "@/servers/api/logInController";

export const useLoginUserStore = defineStore("loginUser", () => {
  const user = ref<API.UserVo>({
    userName: "",
  });

  // const doubleCount = computed(() => user);
  /* eslint-disable */
  function setUser(newUser: any) {
    user.value = newUser;
  }

  async function fetchLoginUser() {
    const res = await getLoginUser();
    if (res != null && res.data != null && res.data.data != null) {
      user.value = res.data.data as API.UserVo;
    }
    // setTimeout(() => {
    //   user.value = {
    //     userName: "123",
    //     id: 2,
    //     userRole: ACCESS_ENUM.ADMIN,
    //   };
    // }, 6000);
  }

  return { user, setUser, fetchLoginUser };
});
